package com.wxy.gxs.springbootprojectday20.controller;

import com.wxy.gxs.springbootprojectday20.bean.Result;
import com.wxy.gxs.springbootprojectday20.bean.User;
import com.wxy.gxs.springbootprojectday20.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 实验目的:
 *  1.练习springboot的视图控制器
 *      具体步骤:
 *          a.自己需要顶一个配置类,配置类的上面需要添加@configulation,实现一个接口,也就是前端控制器的接口
 */

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/method01")
    public String method01(){


        return "这是阶段";
    }


    @RequestMapping("/method02")
    public String method02(){


        return "通过spring boot使用 aop的思想实现日志埋点";
    }

    @RequestMapping(value = "/admin/login/{username}/{password}",method = RequestMethod.GET)
    public Result Login(@PathVariable("username") String usename,  @PathVariable("password") String password){

        User user = userService.findUserByUsernameAndPassword(usename, password);
        Result result = new Result();
        if(user!=null){
           result.setFlag(true);
           result.setMessage("获取用户成功!");
           result.getData().put("data",user);

            return result;
        };

        result.setMessage("信息获取");
        result.setFlag(false);
        result.getData().put("data",null);


        return result;


    }




}
